// pages/chalu/chalu.js

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mealsList: '', //员工工号
    networkUser: '', //总数据
    length: '', //数据长度
    BANK_ASSETS: '', //金额
    USER_ASSETS_NAME: '', //姓名
    USER_COUPON_PHONE: '', //电话
    USER_ASSETS_ID: '', //用户资产ID
    result: '', //判断是否插入成功
    allList: [], //获取的奖券
    COUPON_AMOUNT: '', //选择的数字
    USER_IDCARD: '', //身份证号
    showView: false,
    showView_a: false,
    threeHundred: '', //三百
    hundred: '', //一百
    five: '', //五十
    USER_ASSETS_IDCARD: '', //搜索
    flag: true, //节流
    shujiyou:true,
    xinbiexuan: [{
      xinbie: '100'
    },
    {
      xinbie: '200'
    },
  ],

  xingbie:true,
  prize:'',
  },


 
  xinbie() {
    this.setData({
      xingbie: false
    })
  },


  xin(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.xinbie);

    this.setData({
      prize: e.currentTarget.dataset.item.xinbie,
      xingbie: true,
 
    })
  },



  //拿到单个的钱数
  // watchPassWor: function (e) {
  //   if (!(/(^[0-9]*$)/.test(this.data.BANK_ASSETS))) {
  //     wx.showModal({
  //       title: '温馨提示',
  //       content: "金额只能输入纯数字!",
  //       success: function (res) {
  //         if (res.confirm) {//这里是点击了确定以后
  //           console.log('用户点击确定')
  //         } else {//这里是点击了取消以后
  //           console.log('用户点击取消')
  //         }
  //       }
  //     })
  //     console.log(e);
  //     console.log(e.detail.value);
  //     let value = this.validateNumber(e.detail.value)
  //     this.setData({
  //       BANK_ASSETS: value
  //     })
  //   } else {
  //     wx.request({
  //       url: app.globalData.interface+'/shanyouhui/API_1027_UserCouponAmount',
  //       method: 'POST',
  //       data: {
  //         USER_ASSETS_ID: this.data.USER_ASSETS_ID,
  //         BANK_ASSETS: e.detail.value
  //       },
  //       header: {
  //         'content-type': 'application/x-www-form-urlencoded'
  //       },
  //       success: res => {
  //         console.log(res.data.allList);
  //         this.setData({
  //           allList: res.data.allList
  //         })

  //       }
  //     })
  //   }
  // },
  // validateNumber(val) {
  //   return val.replace(/\D/g, '')
  // },

  //获取单个奖券的数据
  but_shu: function (e) {
    console.log(e.target.dataset.item);
    this.setData({
      COUPON_AMOUNT: e.target.dataset.item
    })

    if (this.data.COUPON_AMOUNT == e.target.dataset.item) {
      this.setData({
        showView_a: (!this.data.showView_a)
      })
    }
  },



  //下拉框的显隐
  but_jq: function () {
    if (this.data.BANK_ASSETS != '') {
      this.setData({
        showView_a: (!this.data.showView_a),
      })
    } else {
      wx.showModal({
        title: '温馨提示',
        content: '请先输入金额',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  },


  //点击显示
  activation: function (e) {

    this.setData({
      showView: (!this.data.showView),
    })

  },
  //刷新页面
  quno() {
    wx.redirectTo({
      url: '../../pages/akyancaojihuo/akyancaojihuo',
    })
  },



  tjok: function () {

    if (this.data.flag) {


      if (this.data.prize == '') {
        wx.showToast({
          title: '请选择金额',
          icon: 'none',
          duration: 3000
        })
      }else{
        console.log(this.data.BANK_ASSETS);
        this.data.flag = false
        setTimeout(() => {
          console.log('-----------------', 1);
          this.data.flag = true
        }, 5000)
        wx.request({
          url: app.globalData.interface+'/ankang/API_5225_activationyancaoprize',
          method: 'POST',
          data: {
            USER_ASSETS_ID: this.data.USER_ASSETS_ID,
            EMPLOYEE_ID: this.data.mealsList,
            USER_ASSETS_IDCARD: this.data.USER_ASSETS_IDCARD,
            openid: this.data.openid,
            prize: this.data.prize,
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: function (res) {
            console.log(res.data.result);
            if (res.data.result != 'success') {
              wx.showModal({
                title: '温馨提示',
                content: res.data.data,
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后
                    console.log('用户点击确定')
                  } else { //这里是点击了取消以后
                    console.log('用户点击取消')
                  }
                }
              })
            } else {
              wx.showModal({
                title: '温馨提示',
                content: res.data.data,
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后
                    wx.redirectTo({
                      url: '../../pages/akyancaojihuo/akyancaojihuo',
                    })
                    console.log('用户点击确定')
                  } else { //这里是点击了取消以后
                    wx.redirectTo({
                      url: '../../pages/akyancaojihuo/akyancaojihuo',
                    })
                    console.log('用户点击取消')
                  }
                }
              })
            }
          }
        })
      }
    }
  },

  search_tow() {
    // this.chaxushu();
    this.setData({
      USER_ASSETS_IDCARD: ''
    })
  },


  search_but() {
    this.setData({
      openid: app.globalData.openid
    })

    var that = this
    wx.request({
      url: app.globalData.interface+'/ankang/API_5227_selectyancaoUser',
      method: 'post',
      data: {
        EMPLOYEE_ID: that.data.mealsList,
        USER_ASSETS_IDCARD: that.data.USER_ASSETS_IDCARD,
        openid: that.data.openid,
        KEY: 'xianjgjKey9999',
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {

        if (res.data.result == 'success') {

          console.log(res);
          console.log(res.data.data);
          //拿到数据
          let shuju = res.data.data
          that.setData({
            networkUser: shuju,
            USER_ASSETS_ID: res.data.data.USER_ASSETS_ID,
            shujiyou:false,
          })
        }
      }
    })
  },




  // chaxushu() {
  //   var that = this
  //   wx.request({
  //     url: app.globalData.interface+'/hundredAnKang/API_5617_networkUserList',
  //     method: 'GET',
  //     data: {
  //       EMPLOYEE_ID: that.data.mealsList
  //     },
  //     header: {
  //       'content-type': 'application/x-www-form-urlencoded'
  //     },
  //     success: res => {
  //       console.log(res.data.networkUser);
  //       //拿到数据
  //       let shuju = res.data.networkUser
  //       // shuju.forEach(function (item, index) {
  //       //   // console.log(index);
  //       // });
  //       // 拿出下标
  //       console.log(Object.keys(shuju).length)
  //       that.setData({
  //         threeHundred: res.data.threeHundred, //三百
  //         hundred: res.data.hundred, //一百
  //         five: res.data.five, //五十
  //         networkUser: shuju,
  //         length: Object.keys(shuju).length,
  //         // USER_ASSETS_ID: res.data.networkUser.USER_ASSETS_ID
  //       })
  //     }
  //   })
  // },

  //验证身份证

  idcardblur: function (e) {
    let idcard = e.detail.value;
    let reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;

    if (reg.test(idcard) == false) {
      this.setData({
        USER_IDCARD: ''
      })
      wx.showToast({
        title: '身份证号码有误',
        icon: 'none',
        duration: 3000
      })
    } else {
      this.setData({
        card_id: idcard
      })
    }
  },









  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    console.log(e);
    this.setData({
      mealsList: app.globalData.mealsList
    });
    console.log(this.data.mealsList);


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {



  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})